package com.fy56.platform.logistics.service.impl;

import com.alibaba.fastjson.JSON;
import com.fy56.platform.logistics.common.InterFaceResult;
import com.fy56.platform.logistics.service.wx.IGmmsCommonService;
import com.fy56.platform.logistics.utils.HttpClientUtils;
import com.fy56.platform.logistics.utils.StringUtil;
import com.google.common.collect.Maps;
import org.springframework.stereotype.Service;

import java.util.Map;

/*
 * @项目名称：
 * @类名称：GmmsCommonServiceImpl
 * @类描述：
 * @创建人：
 * @作者单位：哈尔滨飞扬软件技术有限公司
 * --------------------------------------
 * @创建时间：2019-04-16 16:54:15
 * @version：1.0.0
 */
@Service
public class GmmsCommonServiceImpl implements IGmmsCommonService {

    @Override
    public InterFaceResult getAccessCommonRequestService(String url, String param)throws  Exception{
        InterFaceResult interFaceResult = null;
        // 1 封装参数  访问仓配接口
        Map<String, String> reqMap = Maps.newHashMap();
        reqMap.put("param", param);
        String postData = HttpClientUtils.post(url, reqMap, null, 10000, 10000);
        // 2 判断返回值，解析并封装返回结果
        if(StringUtil.isNotEmpty(postData)){
            interFaceResult = JSON.parseObject(postData).toJavaObject(InterFaceResult.class);
        }
        return interFaceResult;
    }

    @Override
    public InterFaceResult getValidateCodeService(String url, String companyId, String loginName, String phone, String key)throws Exception{
        InterFaceResult interFaceResult = null;
        // 1 封装参数  访问仓配接口
        Map<String, String> reqMap = Maps.newHashMap();
        reqMap.put("companyId", companyId);
        reqMap.put("loginName", loginName);
        reqMap.put("phone", phone);
        reqMap.put("key", key);
        String postData = HttpClientUtils.post(url, reqMap, null, 10000, 10000);
        // 2 判断返回值，解析并封装返回结果
        if(StringUtil.isNotEmpty(postData)){
            interFaceResult = JSON.parseObject(postData).toJavaObject(InterFaceResult.class);
        }
        return interFaceResult;
    }

    @Override
    public InterFaceResult addClientAddOrderService(String url,String param, String sign)throws  Exception{
        InterFaceResult interFaceResult = null;

        Map<String, String> searchParams = Maps.newHashMap();
        searchParams.put("param", param);
        searchParams.put("sign", sign);
        String postData = HttpClientUtils.post(url, searchParams, null, 10000, 10000);
        // 2 判断返回值，解析并封装返回结果
        if(StringUtil.isNotEmpty(postData)){
            interFaceResult = JSON.parseObject(postData).toJavaObject(InterFaceResult.class);
        }
        return interFaceResult;
    }


}
